package player;

import io.IOManager;
import card.*;

/**
 * Class for player
 * 
 * 
 * @version 3.0.2
 */
public class Player {
	/**
	 * name: player's name hand: a cardset of player play: a cardset player
	 * could play in a round id: player's id
	 */
	private String name;
	private Cardset hand;
	private Cardset play;
	private int id;

	private IOManager ioManager;

	/**
	 * Initialize a Player object
	 * 
	 * @param n
	 *            The name of the Player
	 */
	public Player(String n, int id, IOManager ioManager) {
		name = n;
		hand = new Cardset(20);
		play = new Cardset(20);
		this.ioManager = ioManager;
		this.id = id;
	}

	public Player(String n, int id, IOManager ioManager, Cardset hand,
			Cardset play) {
		name = n;
		this.hand = hand;
		this.play = play;
		this.ioManager = ioManager;
		this.id = id;
	}

	public Player(Player p) {
		this.name = p.name;
		this.hand = new Cardset(p.hand);
		this.play = new Cardset(p.play);
		this.ioManager = p.ioManager;
		this.id = p.id;
	}

	/**
	 * @return name
	 */
	public String getName() {
		return new String(name);
	}

	/**
	 * @return id
	 */
	public int getID() {
		return id;
	}

	/**
	 * return the number of cards of the hand of player
	 * 
	 * @return hand.count()
	 */
	public int countHand() {
		return hand.count();
	}

	/**
	 * return the number of cards of the play of player
	 * 
	 * @return
	 */
	public int countPlay() {
		return play.count();
	}

	/**
	 * clear the cardset of hand
	 */
	public void clearHand() {
		hand.clear();
	}

	/**
	 * get the choice of player if he want to be the landlord
	 * 
	 * @return
	 */
	public int landLordRating() {
		return ioManager.ioPlayerLandlordRating(name, hand);
	}

	/**
	 * Tell a player to select the cards for his/her play
	 * 
	 * @return A Cardset of selected Cards
	 */
	public Cardset startTurn() {
		play = ioManager.ioPlayerSelectCards(hand, name);
		return new Cardset(play);
	}

	/**
	 * Perform the action of discarding cards from the hand
	 */
	public void endTurn() {
		if (play.count() > 0) {
			hand.remove(play);
			play.clear();
		}
	}

	/**
	 * Sort the cards on hand
	 */
	public void sortHand() {
		hand.sort();
	}

	/**
	 * Deal a Card object to player's hand
	 * 
	 * @param c
	 *            The Card object
	 * @return Boolean value representing the success or failure of the deal
	 */
	public boolean deckDeal2Hand(Card c) {
		return hand.add(c);
	}
}
